import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 常量路由,任意用户都能操作的路由, 都能看到这个路由组件
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',//这个名字不能和下面meta当中的title重复
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
]

// 异步路由, 权限路由, 用户拥有对应的name信息,这个路由组件才能被用户操作 才能看到
export const allAsyncRoutes = [
  {
    path:'/product',
    component: Layout,
    // redirect: '/product/trademark/list',
    name:'Product',
    meta:{title:'商品管理',icon:'el-icon-s-goods'},
    children:[
      {
        path:'trademark/list',
        component:() => import('@/views/product/trademark/List'),
        name:'Trademark',
        meta:{title:'品牌管理'}
      },
      {
        path:'attr/list',
        component:() => import('@/views/product/attr/List'),
        name:'Attr',
        meta:{title:'平台属性管理'}
      },
      {
        path:'spu/list',
        component:() => import('@/views/product/spu/List'),
        name:'Spu',
        meta:{title:'Spu管理'}
      },
      {
        path:'sku/list',
        component:() => import('@/views/product/sku/List'),
        name:'Sku',
        meta:{title:'Sku管理'}
      },
      {
        path:'scopedTest/list',
        component:() => import('@/views/product/scopedTest/List'),
        name:'ScopedTest',
        meta:{title:'scoped测试'}
      }

    ]
  },
]

export const anyRoute = { path: '*', redirect: '/404', hidden: true }

// 任意路由, 随意的不合法的路由, 全部专项404页面,添加路由器的时候必须最后一个注册



const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
